package com.nutricia.biz.convertor;

import com.nutricia.common.api.info.SystemUserBaseInfo;
import com.nutricia.common.api.info.SystemUserInfo;
import com.nutricia.core.model.domain.SystemUserDO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统用户转换去器。DO和DTO或者INFO的相关转换
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemUserConvertor {


    /**
     * 将SystemUser转换为SystemUserDO
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static SystemUserInfo convertToInfo(final SystemUserDO systemUserDO) {
        if (null == systemUserDO) {
            return null;
        }
        SystemUserInfo systemUserInfo = new SystemUserInfo();
        systemUserInfo.setUserName(systemUserDO.getUserName());
        systemUserInfo.setUserLoginName(systemUserDO.getUserLoginName());
        systemUserInfo.setCreateTime(systemUserDO.getCreateTime());
        systemUserInfo.setCurrentLoginIp(systemUserDO.getCurrentLoginIp());
        systemUserInfo.setCurrentLoginTime(systemUserDO.getCurrentLoginTime());
        systemUserInfo.setId(systemUserDO.getId());
        systemUserInfo.setLastLoginIp(systemUserDO.getLastLoginIp());
        systemUserInfo.setLastLoginTime(systemUserDO.getLastLoginTime());
        systemUserInfo.setUserState(systemUserDO.getUserState());
        systemUserInfo.setCreateName(systemUserDO.getCreateName());
        systemUserInfo.setModifyName(systemUserDO.getModifyName());
        systemUserInfo.setModifyTime(systemUserDO.getModifyTime());
        systemUserInfo.setUserMail(systemUserDO.getUserMail());
        return systemUserInfo;
    }

    /**
     * 将SystemUserDOs转换为SystemUserInfos
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemUserInfo> convertToInfos(final List<SystemUserDO> systemUserDOS) {
        List<SystemUserInfo> SystemUserInfo = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemUserDOS)) {
            systemUserDOS.forEach(systemUserDO -> {
                SystemUserInfo.add(SystemUserConvertor.convertToInfo(systemUserDO));
            });
            return SystemUserInfo;
        }
        return ListUtils.EMPTY_LIST;
    }


    /**
     * 将SystemUser转换为SystemUserDO
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static SystemUserBaseInfo convertToSystemUserBaseInfo(final SystemUserDO systemUserDO) {
        if (null == systemUserDO) {
            return null;
        }
        SystemUserBaseInfo systemUserBaseInfo = new SystemUserBaseInfo();
        systemUserBaseInfo.setUserName(systemUserDO.getUserName());
        systemUserBaseInfo.setUserLoginName(systemUserDO.getUserLoginName());
        systemUserBaseInfo.setId(systemUserDO.getId());
        systemUserBaseInfo.setUserMail(systemUserDO.getUserMail());
        return systemUserBaseInfo;
    }

    /**
     * 将SystemUserDOs转换为SystemUserInfos
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemUserBaseInfo> convertToSystemUserBaseInfos(final List<SystemUserDO> systemUserDOS) {
        List<SystemUserBaseInfo> SystemUserInfo = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemUserDOS)) {
            systemUserDOS.forEach(systemUserDO -> {
                SystemUserInfo.add(SystemUserConvertor.convertToSystemUserBaseInfo(systemUserDO));
            });
            return SystemUserInfo;
        }
        return ListUtils.EMPTY_LIST;
    }
}
